package com.qidian.buy.controller;

import com.qidian.buy.entity.Customer;
import com.qidian.buy.service.CartService;
import com.qidian.buy.util.pojo.QDResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.Servlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;

/**
 * @Author 郭浩
 */
@RestController
@RequestMapping("/cart")
@CrossOrigin
public class CartController {

    @Autowired
    private CartService cartService;
    @RequestMapping("/add")
    public QDResult add(String token, long spId, Long itemId, int quantity, HttpServletRequest request){
        Customer c = (Customer) request.getAttribute("loginCustomer");
        return cartService.add(c,itemId,spId,quantity);
    }

    @RequestMapping("/list")
    public QDResult list(HttpServletRequest request){
        Customer c = (Customer) request.getAttribute("loginCustomer");
        return cartService.list(c);
    }
}
